package butines.game.util;

import butines.core.Vector2f;


public class Smoother {

	private Vector2f sum = new Vector2f();
	private Vector2f[] history;
	private int index = 0;

	public Smoother(int samplesSize) {
		this.history = new Vector2f[samplesSize];
		for (int i = 0; i < history.length; i++) {
			history[i] = new Vector2f();
		}
	}
	
	public Vector2f update(Vector2f value) {
		history[index++].set(value);
	    if (index == history.length) {
	    	index = 0;
	    }
	    sum.set(0, 0);
	    for (Vector2f v: history) {
	    	sum.add(v);
	    }
		sum.div(history.length);	
		return sum;
	}
	
	
}
